﻿namespace Refract.Extensions
{
    using System;
    using System.Collections.Generic;

    /// <summary>
    /// Extensions for IList types
    /// </summary>
    public static class ListExtensions
    {
        #region Methods

        /// <summary>
        /// Removes all items in an IList meeting the specified criteria.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="list">The list.</param>
        /// <param name="criteria">The criteria.</param>
        public static void RemoveAll<T>(this IList<T> list, Predicate<T> criteria)
        {
            for (int i = list.Count - 1; i >= 0; i--)
            {
                if (criteria(list[i])) list.RemoveAt(i);
            }
        }

        #endregion Methods
    }
}